package com.xique.system.api.factory;

import com.xique.common.core.domain.R;
import com.xique.system.api.RemoteSystemDictService;
import com.xique.system.api.dto.SystemDictDataDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

/**
 * @author shd
 * @create 2021/12/29 10:21
 */
public class RemoteSystemDictFallbackFactory implements FallbackFactory<RemoteSystemDictService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSystemDictFallbackFactory.class);

    @Override
    public RemoteSystemDictService create(Throwable throwable) {

        log.error("服务调用失败:{}", throwable.getMessage());
        return new RemoteSystemDictService()
        {
            @Override
            public R<String> getDictLabel(String dictType, String dictValue) {
                return R.fail("获取字典失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SystemDictDataDTO>> getDictDataByType(String dictType) {
                return R.fail("获取字典值失败:" + throwable.getMessage());
            }
        };
    }
}
